package com.yuanluludev.app.room.student

import androidx.room.*

@Dao
interface StudentDao {

    /**
     * 插入一部分学生
     */
    @Transaction
    @Insert(entity = Student::class,onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertStudents(vararg students: Student)

    /**
     * 插入一个学生 （最好返回Long）
     */
    @Transaction
    @Insert(entity = Student::class, onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertStudent(student: Student): Long

    /**
     * 查询所有学生
     */
    @Transaction
    @Query("select * from student")
    suspend fun queryAllStudent(): List<Student>

    /**
     * 模糊查询
     */
    @Transaction
    @Query("select * from student where name like :nameLike")
    suspend fun queryStudentLikeName(nameLike: String): List<Student>

    /**
     * 根据ID查询学生
     */
    @Transaction
    @Query("select * from student where uid = :uid")
    suspend fun queryStudentByUid(uid: Long): Student?

    /**
     *  根据ID降序查询所有学生
     */
    @Transaction
    @Query("select * from student order by uid desc")
    suspend fun queryAllStudentOrderByUidDesc(): List<Student>

    /**
     * 更新一个学生
     */
    @Transaction
    @Update(entity = Student::class)
    suspend fun updateStudent(student: Student)

    /**
     * 删除一个学生
     */
    @Transaction
    @Delete(entity = Student::class)
    suspend fun deleteStudent(student: Student)

    /**
     * 删除一个学生 根据ID
     */
    @Transaction
    @Query("delete from student where uid = :uid")
    suspend fun deleteStudentByID(uid: Long)

    /**
     * 删除所有学生
     */
    @Query("delete from student")
    suspend fun deleteAllStudent()

}